import 'package:json_annotation/json_annotation.dart';

part 'Result.g.dart';

@JsonSerializable(genericArgumentFactories: true)
class Result<T> {
  int? code;
  String? message;
  T? data;

  Result();

  factory Result.fromJson(
      Map<String, dynamic> json, T Function(Object? json) fromJsonT) {
    return _$ResultFromJson(json, fromJsonT);
  }

  Map<String, dynamic> toJson(
      Result<T> instance, Object? Function(T value) toJsonT) {
    return _$ResultToJson(instance, toJsonT);
  }

  bool isSuccess() {
    return code == 0;
  }

  @override
  String toString() {
    return 'Result{code: $code, message: $message, data: $data}';
  }
}
